import sys

baseFile = open(sys.argv[1], "r")
wekaFile = open(sys.argv[2], "w")

cromossomo = sys.argv[3]
stringLength = len(cromossomo)

# The first file line contains the relation's name
relation = baseFile.readline()
wekaFile.write(relation)

# Second line in empty, just discart it
baseFile.readline()
wekaFile.write("\n")

for i in range(stringLength):

    line = baseFile.readline()
    if cromossomo[i] == '1':

        wekaFile.write(line)

# The next line is the class atributtes
line = baseFile.readline()
wekaFile.write(line)

baseFile.readline()
wekaFile.write("\n")

# data line
line = baseFile.readline()
wekaFile.write(line)

#baseFile.readline() #tava comendo uma linha dos dados aqui...
#wekaFile.write("\n")

for line in baseFile:

    for i in range(stringLength):

        data = line.rsplit(',')[i]
        if cromossomo[i] == '1':

            wekaFile.write(data + ',')

    wekaFile.write(line.rsplit(',')[-1])
